package com.example.myapplication;

import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.text.format.Formatter;
import android.view.View;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.myapplication.tools.EngineUtils;

import java.io.File;
import java.util.List;

/**
 * 作者：Administrator
 * 创建时间：2020/6/24
 */
public class AppAdapter extends BaseQuickAdapter<AppInfo, BaseViewHolder> {
    public AppAdapter(int layoutResId, List<AppInfo> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, AppInfo item) {

        helper.setImageDrawable(R.id.iv_icon,item.getIcon(getContext()));
        helper.setText(R.id.tv_appname,item.getAppName(getContext()));
        helper.setText(R.id.tv_apppath,item.getPath());
        helper.setText(R.id.tv_size,item.getFileSizeString(getContext()));


        helper.setGone(R.id.ll_tools,!item.isOpen());
        helper.setGone(R.id.line_bottom,!item.isOpen());

        helper.getView(R.id.rl_start).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getContext(), "启动"+item.getAppName(getContext()), Toast.LENGTH_SHORT).show();
                EngineUtils.startApplication(getContext(),item);
            }
        });
        helper.getView(R.id.rl_uninstall).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getContext(), "卸载"+item.getAppName(getContext()), Toast.LENGTH_SHORT).show();
            }
        });
        helper.getView(R.id.rl_share).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(getContext(), "分享"+item.getAppName(getContext()), Toast.LENGTH_SHORT).show();
                EngineUtils.sharedApplication(getContext(),item);
            }
        });
    }
}